package com.zhongyu.controller;

import com.zhongyu.pojo.Permission;
import com.zhongyu.pojo.Role;
import com.zhongyu.pojo.User;
import com.zhongyu.service.PermissionService;
import com.zhongyu.service.RoleService;
import com.zhongyu.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import java.util.List;
/*
首页
 */
@Controller
public class IndexController {
@Resource
private PermissionService permissionService;
@Resource
private UserService userService;
    @Resource
    private RoleService roleService;
   @GetMapping("/index")
    public String index(Model model) {
       Subject subject= SecurityUtils.getSubject();
       User user= (User) subject.getPrincipal();
       Session session=subject.getSession();
       session.setAttribute("loginUser",user);
       List<Role> list1= roleService.searchById(user.getUserRole());
       Role role1= list1.get(0);
       session.setAttribute("loginRole",role1);
      List<Permission> list= permissionService.searchMenuList();
       model.addAttribute("menuList",list);
        return "index";
    }
}
